<?php

namespace app\servercomment\service\comment;
use app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-06-13 14:18:14
 * @Description: 评论
 */

class CommentReply extends ApiBase
{
	
	protected $commentLogic = 'app\servercomment\logic\Comment';
	protected $commentReplyLogic = 'app\servercomment\logic\CommentReply';
    protected $commentReplyValidate = 'app\servercomment\validate\CommentReply';
    protected $addFields = ['comment_id'=>0,'reply_id'=>0,'user_id'=>0,'content'=>' ','orther_info'=>''];

    /*A用户回复B用户对某文章的评论*/
    public function replyComment(): array 
    {
    	$data = $this->haveIssetReceiveData($this->addFields);

    	$validate = validate($this->commentReplyValidate);
        if(!$validate->check($data)){
            return verify_err(null, $validate->getError());
        }

    	$comment = logic($this->commentLogic)->dbCommontInfo(['id'=>$data['comment_id']]);
    	if(!$comment){
    		return verify_err(null, '该评论不存在');
    	}

        if($data['reply_id']){   /*回复的某一回复*/
            $reply = $this->logic($this->commentReplyLogic)->dbReplyInfo(['id'=>$data['reply_id']]);
            if(!$reply){
                return verify_err(null, '要回复的该回复内容不存在');
            }
            if($reply['comment_id'] != $data['comment_id']){
                return verify_err(null, '该回复不属于该评论');
            }
            $data['to_user'] = $reply['user_id'];
        }else{     /*回复的某一评论*/
            $data['to_user'] = $comment['user_id'];
        }

        if($data['to_user'] == $data['user_id']){
            return verify_err(null, '不可回复自己');
        }

    	return $this->logic($this->commentReplyLogic)->replyComment($data);
    }

    

    
}






